package com.example.haiti_infrastructure_prototype;

import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.app.Activity;
import android.content.ContentValues;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;

public class PhotoActivity extends Activity {

	// Creates camera call request code
	private static final int CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE = 100;

	
	@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_photo);
        
        //Sets click listener for questionnaire button
        Button btnPhoto = (Button)findViewById(R.id.btnTakePhoto);
        btnPhoto.setOnClickListener(photoButton);   
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;                         
    }
    
  //---create an anonymous class to act as a button click listener---
    private OnClickListener photoButton = new OnClickListener()
    {
        public void onClick(View v)
        {                         
           /* Toast.makeText(getBaseContext(), 
                    "Next Page!", 
                    Toast.LENGTH_LONG).show();
            */         
        	startCamera();
        }
    
    public void startCamera() {
    	
    	//defines the filename
    	String fileName = "test.jpg";
    	
    	//create parameters for Intent with filename
    	ContentValues values = new ContentValues();
    	values.put(MediaStore.Images.Media.TITLE, fileName);
    	values.put(MediaStore.Images.Media.DESCRIPTION,"Test Image");
    	
    	//create new Intent
    	Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    	startActivityForResult(intent, CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE);   
    	}
    
    }; 	
    
    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {        
        if (requestCode == CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE) {
            if (resultCode == Activity.RESULT_OK) {
            	 Toast.makeText(getBaseContext(), 
                "Picture Successfully Taken!", 
                Toast.LENGTH_LONG).show();
          

            } else if (resultCode == Activity.RESULT_CANCELED) {
                // User cancelled the image capture
            } else {
                // Image capture failed, advise user
            }
        }               
    }

}
